<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page import="com.pptree.vo.*" %>
<%@ page import="com.pptree.service.*" %>
<%@ page import="com.pptree.service.impl.*" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>新闻信息管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
<style type="text/css">
		.gridview {
			 border: 1px solid #1E82D1;
			 border-collapse: collapse;
			 width: 100%;
			 font-size:9pt;
		}
		
		.gridview th {
			height: 30px;
			line-height: 30px;
			background: #1E82D1;
			border: 1px solid #1E82D1;
			color:#fff;
			font-size:14px;
		}
		
		.gridview td {
			height:28px;
			border: 1px solid #1E82D1;
			text-align: center;
		}
		
		.gridview .btn{
			height: 30px;
			line-height:30px;
			width: 80px;
			display: inline-block;
			background: #1E82D1;
			color:#fff;
			text-align: center;
			text-decoration: none;
			border-radius: 15px;
		}
		
		.paging a{
			background: #1E82D1;
			color:#fff;
			width:60px;
			height:25px;
			display: inline-block;
			text-decoration: none;
			line-height: 25px;
			border-radius: 8px;
			padding:2px;
			margin-right: 5px;
		}
	</style>
  </head>
  
  <body>
  	<table class="gridview">
  		<tr>	
  			<th>编号</th>
  			<th>主题</th>
  			<th>标题</th>
  			<th>作者</th>
  			<th>创建日期</th>
  			<th>修改日期</th>
  			<th>操作</th>
  		</tr>
  		<%
  			String curPageNo = request.getParameter("pageno");
  			if(curPageNo == null || "".equals(curPageNo)){
  				curPageNo = "1";
  			}
  			
  			int pageIndex = Integer.valueOf(curPageNo); //获得当前页页码
  			
  			NewsService newsService = new NewsServiceImpl();
  			
  			PageVo<NewsDomain> pageVo = newsService.findByPaging(pageIndex, 5);
  			
  			int totalpages = pageVo.getTotalpage(); //获得总页数
  			
  			request.setAttribute("pageIndex", pageIndex);
  			request.setAttribute("totalpages", totalpages);
  			for(NewsDomain news : pageVo.getList()) { %>
  			<tr>
  				<td><%= news.getId() %></td>
  				<td><%= news.getTname() %></td>
  				<td><%= news.getTitle() %></td>
  				<td><%= news.getAuthor() %></td>
  				<td><%= news.getCreatedate().toLocaleString() %></td>
  				<td><%= news.getModifydate()==null ? "" : news.getModifydate().toLocaleString() %></td>
  				<td>
  					<a class="btn" href="#">修 改</a>
  					<a class="btn" href="#" onclick="return confirm('确定要删除此新闻吗？')">删 除</a>
  				</td>
  			</tr>
  		<% } %>
  		
  		<!-- 分页导航 -->
  		<tr>
  			<td colspan="7" class="paging">
  				当前页数：[<%=pageIndex%>/<%=totalpages%>]
  				
  					<c:choose>
  						<c:when test="${ pageIndex > 1 }">
  							<a href="admin/newsList.jsp?pageno=1">首页</a>
  							<a href="admin/newsList.jsp?pageno=${ pageIndex - 1}">上一页</a>
  						</c:when>
  						<c:otherwise>
  							<a href="javascript:;">首页</a>
  							<a href="javascript:;">上一页</a>
  						</c:otherwise>
  					</c:choose>
  				
  				<c:forEach begin="1" end="5" step="1" var="pageNum">
  					<a href="#">${ pageNum }</a>
  				</c:forEach>
  				
  				  <c:choose>
  				  	<c:when test="${ pageIndex < totalpages }">
	  				  	<a href="admin/newsList.jsp?pageno=${ pageIndex + 1}">下一页</a>
	  					<a href="admin/newsList.jsp?pageno=${ totalpages }">末页</a>
  				  	</c:when>
  				  	<c:otherwise>
  							<a href="javascript:;">下一页</a>
  							<a href="javascript:;">末页</a>
  						</c:otherwise>
  				  </c:choose>
  			</td>
  		</tr>
  	</table>
  </body>
</html>
